//请求类
var request = {};
//get请求
request.get = function(url, data, fn) {
	if(typeof data == "function") {
		fn = data;
		data = {};
	}
	if(data == "") {
		data = {};
	}
	$.ajax({
		type: "GET",
		url: url,
		data: data,
		dataType: 'json',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(result) {
			if(result.code == 400) {
				layui.layer.msg(result.mes);
				return;
			}

			fn(result);
		}
	});

};
//post请求
request.post = function(url, data, fn) {
	if(typeof data == "function") {
		fn = data;
		data = {};
	}
	if(data == "") {
		data = {};
	}
	$.ajax({
		type: "POST",
		url: url,
		data: data,
		dataType: 'json',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(result) {
			if(result.code == 400) {
				layui.layer.msg(result.mes);
				return;
			}

			fn(result);
		}
	});

};